import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

@Injectable()
export class LoginService {

  private api_url = 'http://xcms.0715ym.com/admin/login';

  constructor(private http: HttpClient,
  ) { }

  login(formData) {
    let params = new HttpParams;
    for (const i in formData) {
      params = params.set(i,formData[i]);
    }
    return this.http
      .post(this.api_url, params.toString(), {
        headers: new HttpHeaders().set('content-Type', 'application/x-www-form-urlencoded'),
        withCredentials: true
      });      
  }

  logout() {
    return this.http
      .get(this.api_url+'/out',{ 
        withCredentials: true
      });
  }
  
}
